<%--
  Created by IntelliJ IDEA.
  User: 邹敦宇
  Date: 2021/3/1
  Time: 8:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<%
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<base href="<%=basePath%>">
<link rel="stylesheet" href="static/layui/css/layui.css">
<link rel="stylesheet" href="static/css/admin.css">
<link rel="stylesheet" href="static/css/login.css">
<body>


<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>爱购网</h2>
            <p>后台管理员登录</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                        <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                           <img src="/eshop/captcha" class="layadmin-user-login-codeimg" id="vcode">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
            </div>
        </div>
    </div>
</div>
<script src="static/layui/layui.js"></script>
<script>
    layui.config({
        base: '/eshop/static/layui/' //静态资源所在路径
    })
    layui.use('form', function(){
        var form = layui.form,layer = layui.layer;
        var $ = layui.$;//通过layui获取到jquery
        //监听提交
        form.on('submit(LAY-user-login-submit)', function(obj){
                $.ajax({
                    url:'/eshop/Users.do?m=login',
                    type:'post',
                    data:obj.field,
                    dataType:'json',
                    success:function (data){

                        layer.msg(JSON.stringify(data))
                        if (data=='后台用户'){
                            layer.msg(JSON.stringify("登录成功"))
                            location.href='admin/index.jsp'
                        }else if(data=='前台用户'){
                            layer.msg(JSON.stringify('请去前台登录'))
                        }else{
                            $("#vcode").attr("src","/eshop/captcha?"+Math.random())
                        }
                    }
                })
        });
        <c:if test="${not empty msg}">
        layer.msg(JSON.stringify('${msg}'))
        </c:if>
        $("#vcode").click(function () {
            $("#vcode").attr("src","/eshop/captcha?"+Math.random())
        })


    })

</script>
</body>
</html>
